package com.nsu.edu.androidmvpdemo.login;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.nsu.edu.androidmvpdemo.R;
import com.nsu.edu.androidmvpdemo.login.Presenter.ILoginPresenter;
import com.nsu.edu.androidmvpdemo.login.Presenter.LoginPresenterImpl;
import com.nsu.edu.androidmvpdemo.login.View.ILoginView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者： andli
 * 时间： 2017/12/6 16:53
 * 描述： 首页
 */
public class LoginActivity extends Activity implements ILoginView{

    @BindView(R.id.username)
    EditText username;

    @BindView(R.id.password)
    EditText password;

    @BindView(R.id.button)
    Button button;

    @BindView(R.id.progress)
    ProgressBar progressBar;

    // 逻辑处理
    private ILoginPresenter presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);

        presenter = new LoginPresenterImpl(this);
    }

    @OnClick(R.id.button)
    public void onViewClicked() {
        // 验证登录
        presenter.validateCredentials(username.getText().toString(), password.getText().toString());

    }

    @Override
    public void showProgress() {
        progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideProgress() {
        progressBar.setVisibility(View.GONE);
    }

    @Override
    public void setUsernameError() {
        username.setError(getString(R.string.username_error));
    }

    @Override
    public void setPasswordError() {
        password.setError(getString(R.string.password_error));
    }

    @Override
    public void navigateToHome() {
        // 登录成功
        Toast.makeText(this, "登录成功！", Toast.LENGTH_SHORT).show();
    }


}
